<?php
namespace Home\Controller;
use Think\Controller;
class SearchController extends Controller {
    //搜索 默认页
    public function index(){
        //设置页面的标题等
        $data['title']='搜索 找金银网';
        $Model=D("Product");
        //获取传递的参数
        if(I('path.2')!=''){
            $keyword=I('path.2');
        }
        if(I('path.3')>0){
            $page=I('path.3');
        }else{
            $page=1;
        }
        $perpage=10;
        //获取左侧分类列表
        //$cat_list=$ArticleClass->get_cat_list();
        //获取文章列表及分页
        $Model->keyword=$keyword;
        $Model->page=$page;
        $Model->perpage=$perpage;
        //$Model->ac_id=$ac_id;
        $product_list=$Model->get_product_list();  //文章列表
        print_r($product_list);exit;
        $product_total=$Model->get_product_total(); //文章总数
        $page_total=ceil($product_total/$perpage);  //分页总数
        //分页数据
        if($page!=1&&$page_total>1){
            $last_page=$page-1;
        }else{
            $last_page=1;
        }
        if($page_total>$page){
            $next_page=$page+1;
        }else{
            $next_page=$page;
        }
        $pager['current_page']=$page;
        $pager['last_page']=$last_page;
        $pager['next_page']=$next_page;
        $pager['page_total']=$page_total;
        $pager['article_total']=$article_total;
        $this->assign("data", $data);
        //$this->assign("cat_list", $cat_list);
        $this->assign("product_list", $product_list);
        $this->assign("pager",$pager);
        $this->display();
    }
    //搜索 首页传入关键词参数
    public function search_goods($keyword,$page=1,$city_id='',$brand_id='',$province_id='',$sort=''){
        //设置页面的标题等
        $data['title']='搜索 找金银网';
        $Model=D("Product");
        $url=array();
        $base_url='/search/search_goods';
        //echo $base_url;exit;
        //关键词及页数
        if($keyword!=''){
            $keyword=addslashes($keyword);
            //echo $keyword;exit;
            $Model->keyword=$keyword;
            $base_url.='/keyword/'.$keyword;
        }
        if(intval($page)==0){
            $page=1;
        }else{
            $page=intval($page);
        }
        //筛选
        if($city_id!=''){
            if(intval($city_id)>0){
                $city_id=intval($city_id);
            }elseif(intval($city_id)==0){
                $city_id=5;
            }
            $Model->city_id=$city_id;
            $city_url='/city_id/'.$city_id;
        }
        if($brand_id!=''){
            if(intval($brand_id)>0){
                $brand_id=intval($brand_id);
            }elseif(intval($brand_id)==0){
                $brand_id=17;
            }
            $Model->brand_id=$brand_id;
            $brand_url='/brand_id/'.$brand_id;
        }
        if($province_id!=''){
            if(intval($province_id)>0){
                $province_id=intval($province_id);
            }elseif(intval($province_id)==0){
                $province_id=4;
            }
            $Model->province_id=$province_id;
            $province_url='/province_id/'.$province_id;
        }
        $url['city_url']=$base_url.$brand_url.$province_url;
        $url['brand_url']=$base_url.$city_url.$province_url;
        $url['province_url']=$base_url.$city_url.$brand_url;
        $url['self_url']=__SELF__;
        //排序
        if($sort!=''){
            $sort=addslashes($sort);
            if($sort=='sell_num-desc'){
                $search_sort='product_num desc';
            }
            if($sort=='sell_num-asc'){
                $search_sort='product_num asc';
            }
            if($sort=='price-desc'){
                $search_sort='product_price desc';
            }
            if($sort=='price-asc'){
                $search_sort='product_price asc';
            }
            if($sort=='add_time-desc'){
                $search_sort='product_time desc';
            }
            if($sort=='add_time-asc'){
                $search_sort='product_time asc';
            }
            $Model->search_sort=$search_sort;
        }
        //echo __SELF__;exit;
        //print_r($url);exit;
        //echo $page.'<br />';
        //echo $city_id.'<br/>';
        //echo $brand_id.'<br/>';
        //echo $province_id.'<br/>';exit;
        $perpage=10;
        //获取左侧分类列表
        //$cat_list=$ArticleClass->get_cat_list();
        //获取文章列表及分页
        $Model->page=$page;
        $Model->perpage=$perpage;
        //$Model->ac_id=$ac_id;
        $product_list=$Model->get_product_list();  //文章列表
        //echo __SELF__;exit;
        //print_r($product_list);exit;
        $product_total=$Model->get_product_total(); //文章总数
        $page_total=ceil($product_total/$perpage);  //分页总数
        //分页数据
        if($page!=1&&$page_total>1){
            $last_page=$page-1;
        }else{
            $last_page=1;
        }
        if($page_total>$page){
            $next_page=$page+1;
        }else{
            $next_page=$page;
        }
        $pager['current_page']=$page;
        $pager['last_page']=$last_page;
        $pager['next_page']=$next_page;
        $pager['page_total']=$page_total;
        $pager['product_total']=$product_total;
        //print_r($pager);exit;
        $this->assign("data", $data);
        //$this->assign("cat_list", $cat_list);
        $this->assign("product_list", $product_list);
        $this->assign("pager",$pager);
        $this->assign("url",$url);
        $this->display();
    }
    /*//新闻中心 新闻列表
    public function news_list(){
        //设置页面的标题等
        $data['title']='新闻中心 找金银网';
        $Model=D("Article");
        $ArticleClass=D("ArticleClass");
        //获取传递的参数
        if(I('path.2')>0){
            $ac_id=I('path.2');
        }else{
            $ac_id=1;
        }
        if(I('path.3')>0){
            $page=I('path.3');
        }else{
            $page=1;
        }
        $perpage=10;
        //获取左侧分类列表
        $ArticleClass->ac_id=$ac_id;
        $cat_list=$ArticleClass->get_cat_list();
        $ac_info=$ArticleClass->get_ac_info();
        //print_r($ac_info);exit;
        //获取文章列表及分页
        $Model->page=$page;
        $Model->perpage=$perpage;
        $Model->ac_id=$ac_id;
        $article_list=$Model->get_article_list();  //文章列表
        //print_r($article_list);exit;
        $article_total=$Model->get_article_total(); //文章总数
        $page_total=ceil($article_total/$perpage);  //分页总数
        //分页数据
        if($page!=1&&$page_total>1){
            $last_page=$page-1;
        }else{
            $last_page=1;
        }
        if($page_total>$page){
            $next_page=$page+1;
        }else{
            $next_page=$page;
        }
        $pager['current_page']=$page;
        $pager['last_page']=$last_page;
        $pager['next_page']=$next_page;
        $pager['page_total']=$page_total;
        $pager['article_total']=$article_total;
        $this->assign("data", $data);
        $this->assign("cat_list", $cat_list);
        $this->assign("article_list", $article_list);
        $this->assign("pager",$pager);
        $this->assign("ac_info",$ac_info);
        $this->display();
    }
    //新闻中心 新闻详情
    public function news_view(){
        //设置页面的标题等
        $data['title']='新闻中心 找金银网';
        $Model=D("Article");
        $ArticleClass=D("ArticleClass");
        //获取传递的参数
        if(I('path.2')>0){
            $article_id=I('path.2');
        }else{
            $article_id=1;
        }
        if(I('path.3')>0){
            $page=I('path.3');
        }else{
            $page=1;
        }
        $perpage=10;
        //获取左侧分类列表
       // $ArticleClass->ac_id=$ac_id;
        $cat_list=$ArticleClass->get_cat_list();
        //$ac_info=$ArticleClass->get_ac_info();
        //print_r($cat_list);exit;
        //获取文章列表及分页
        $Model->page=$page;
        $Model->perpage=$perpage;
        $Model->article_id=$article_id;
        $article_info=$Model->get_article_info();
        $Model->ac_id=$article_info['ac_id'];
        $last_article=$Model->get_last_article();
        $next_article=$Model->get_next_article();
        //print_r($next_article);exit;

        $this->assign("data", $data);
        $this->assign("cat_list", $cat_list);
        $this->assign("article_info", $article_info);
        $this->assign("last_article", $last_article);
        $this->assign("next_article", $next_article);
        $this->display();
    }*/

}